package com.weixt.serial;

import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import gnu.io.SerialPort;
import gnu.io.UnsupportedCommOperationException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RestController;

import java.time.temporal.Temporal;
import java.util.List;

@SpringBootApplication
@RestController
public class SerialApplication {

    public static void main(String[] args) {
        SpringApplication.run(SerialApplication.class, args);

        List<String> serialPortList = SerialPortUtils.getSerialPortList();
        for (String s : serialPortList) {
            System.out.println(s);
        }

        try {
            /**
             * 打开 usb 串口
             */
            SerialPort serialPort = SerialPortUtils.openSerialPort("/dev/ttyUSB0");
            /**
             * 设置声音大小
             */
//            SerialPortUtils.sendData(serialPort, SerialHexUtils.getSerialPortSetting("20032086", 1));
            /**
             * 播报声音内容
             */
            SerialPortUtils.sendData(serialPort, SerialHexUtils.getSerialPortContent("20032086", "声音测试"));
        } catch (NoSuchPortException e) {
            e.printStackTrace();
        } catch (PortInUseException e) {
            e.printStackTrace();
        } catch (UnsupportedCommOperationException e) {
            e.printStackTrace();
        }

    }



}
